<?php
  /**
   * @author 2mdc.com
   * @version 
   */

  include_once dirname(__FILE__) . '/cCreateElement.inc';

  class cCreateEndnote extends cCreateElement {
    static private $rscInstance = NULL;
    static private $intId;
    static public $boolInit = 0;

    private function __construct() {
    }

    public function __destruct() {
    }

    public function __toString() {
      return $this->xml;
    }

    static public function getInstance() {
       if(self::$rscInstance == NULL) {
          self::$rscInstance = new cCreateEndnote();
       }
       return self::$rscInstance;
    }

    protected function fGenerateENDNOTE($strType) {
      self::$boolInit = 1;
      if(empty(self::$intId)) {
        self::$intId = 1;
      }
      else {
        self::$intId++;
      }
      $xmlAux = '<'.cCreateElement::NAMESPACE.':endnote';
      if($strType != '')
      	$xmlAux .= ' '.cCreateElement::NAMESPACE.':type="'.$strType.'"'; 
      $this->xml = $xmlAux . ' '.cCreateElement::NAMESPACE.':id="'.(self::$intId - 2).'">__GENERATEENDNOTE__</'.cCreateElement::NAMESPACE.':endnote>';
    }

    protected function fGeneratePPR() {
      $this->xml = str_replace('__GENERATEP__', '<'.cCreateElement::NAMESPACE.':pPr>__GENERATEPPR__</'.cCreateElement::NAMESPACE.':pPr>__GENERATEP__', $this->xml);
    }
    

    protected function fGenerateP($rsidR = '005F02E5', $rsidRDefault = '005F02E5', $rsidP = '005F02E5') {
      $this->xml = str_replace('__GENERATEENDNOTE__', '<'.cCreateElement::NAMESPACE.':p>__GENERATEP__</'.cCreateElement::NAMESPACE.':p>', $this->xml);
    }

    protected function fGenerateSEPARATOR($strType = 'separator') {
      $this->xml = str_replace('__GENERATER__', '<'.cCreateElement::NAMESPACE.':'.$strType.'></'.cCreateElement::NAMESPACE.':'.$strType.'>', $this->xml);
    }

    protected function fGenerateSPACING($intAfter = '0', $intLine = '240', $strLineRule = 'auto') {
      $this->xml = str_replace('__GENERATEPPR__', '<'.cCreateElement::NAMESPACE.':spacing w:after="'.$intAfter.'" '.cCreateElement::NAMESPACE.':line="'.$intLine.'" '.cCreateElement::NAMESPACE.':lineRule="'.$strLineRule.'"></'.cCreateElement::NAMESPACE.':spacing>', $this->xml);
    }
    
    protected function fGenerateR() {
      $this->xml = str_replace('__GENERATEP__', '<'.cCreateElement::NAMESPACE.':r>__GENERATER__</'.cCreateElement::NAMESPACE.':r>__GENERATEP__', $this->xml);
    }
    
    protected function fGenerateENDNOTEREF() {
      $this->xml = str_replace('__GENERATER__', '<'.cCreateElement::NAMESPACE.':endnoteRef></'.cCreateElement::NAMESPACE.':endnoteRef>', $this->xml);
    }
  
    protected function fGenerateENDNOTEREFERENCE($id = '') {
      $this->xml = str_replace('__GENERATER__', '<'.cCreateElement::NAMESPACE.':endnoteReference '.cCreateElement::NAMESPACE.':id="' . $id . '"></'.cCreateElement::NAMESPACE.':endnoteReference>', $this->xml);
    }
    
  	public function fCreateEndnote() {
      $this->xml = '';
      $arrArgs = func_get_args();
      $this->fGenerateENDNOTE('');
      $this->fGenerateP();
      $this->fGeneratePPR();
      $this->fGeneratePSTYLE();
      $this->fGenerateR();
      $this->fGenerateRPR();
      $this->fGenerateRSTYLE();
      $this->fGenerateENDNOTEREF();
      $this->fGenerateR();
      $this->fGenerateT($arrArgs[0]['textEndNote']);
      $this->fCleanTemplate();
    }
    
  	public function fCreateDocumentEndnote() {
      $this->xml = '';
      $arrArgs = func_get_args();
      parent::fGenerateP();
      $this->fGenerateR();
      $this->fGenerateT($arrArgs[0]['textDocument']);
      $this->fGenerateR();
      $this->fGenerateRPR();
      $this->fGenerateRSTYLE();
      $this->fGenerateENDNOTEREFERENCE(self::$intId-2);
      $this->fCleanTemplate();
    }
    
    public function fCreateInitEndnote() {
      $this->xml = '';
      $arrArgs = func_get_args();
      $this->fGenerateENDNOTE($arrArgs[0]['type']);
      $this->fGenerateP();
      $this->fGeneratePPR();
      $this->fGenerateSPACING();
      $this->fGenerateR();
      $this->fGenerateSEPARATOR($arrArgs[0]['type']);
      $this->fCleanTemplate();
    }
  }
?>